#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int kMaxN = 20;
const int kMaxM = 100;

bool used[kMaxN][kMaxN];
int color[kMaxN];
pair<int, int> e[kMaxM];
vector<int> g[kMaxN];
bool del[kMaxN];

void Merge(int a, int b, int n) {
  int minc = min(color[a], color[b]), maxc = max(color[a], color[b]);

  if (maxc != minc) {
    for (int i = 1; i <= n; i++) {
      if (color[i] == maxc) {
        color[i] = minc;
      }
    }
  }
}

vector<int> tmp;

void DFS1(int now) {
  del[now] = true;
  tmp.emplace_back(now);
  for (int next : g[now]) {
    if (!del[next]) {
      DFS1(next);
    }
  }
}

int type[kMaxN];
int cnt = 0;
void DFS2(int dep) {
  if (dep == tmp.size()) {
    cnt++;
    return;
  }

  int now = tmp[dep];
  for (int i = 0; i < 3; i++) {
    type[now] = i;
    bool succ = true;
    for (int v : g[now]) {
      if (v < now && type[v] == type[now]) {
        succ = false;
        break;
      }
    }
    if (succ) {
      DFS2(dep + 1);
    }
  }
}

int main() {
  freopen("assign.in", "r", stdin);
  freopen("assign.out", "w", stdout);
  int n, m;

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    color[i] = i;
  }

  int tot = 0;
  for (int i = 0; i < m; i++) {
    string s;
    int a, b;
    cin >> s >> a >> b;
    if (s == "S") {
      Merge(a, b, n);
    } else {
      e[tot++] = make_pair(a, b);
    }
  }

  for (int i = 0; i < tot; i++) {
    int u = color[e[i].first], v = color[e[i].second];

    if (u == v) {
      cout << "0\n";
      return 0;
    }
    if (!used[u][v]) {
      used[u][v] = used[v][u] = true;
      g[u].emplace_back(v);
      g[v].emplace_back(u);
    }
  }

  int ans = 1;

  for (int i = 1; i <= n; i++) {
    if (color[i] == i && del[i] == false) {
      tmp.clear();
      DFS1(i);

      sort(tmp.begin(), tmp.end());
      cnt = 0;
      DFS2(1);
      ans = ans * cnt * 3;
    }
  }

  cout << ans << "\n";
  return 0;
}